package com.pignest.hotel.spring;

import java.util.ArrayList;
import java.util.Hashtable;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

import org.zkoss.zk.ui.http.HttpSessionListener;

@Deprecated
public class ZkHttpSessionListener extends HttpSessionListener implements HttpSessionBindingListener {

	private Hashtable<String, HttpSession> sessionTable; 
	private Hashtable<String, String> logIdTable;
	private Hashtable<String, String> logoutMemoTable;
	
	public ZkHttpSessionListener() {
		sessionTable = new Hashtable<String, HttpSession>(4096);
		logIdTable = new Hashtable<String, String>(4096);
		logoutMemoTable = new Hashtable<String, String>(4096);
	}

	public int getSessionSize() {
		return sessionTable.size();
	}

	public ArrayList<HttpSession> getUserSessionList() {
		ArrayList<HttpSession> list = new ArrayList<HttpSession>();
		list.addAll(sessionTable.values());
		return list;
	}

	public void valueBound(HttpSessionBindingEvent arg0) {
		sessionTable.put(arg0.getSession().getId(), arg0.getSession());
	}

	public void putLogId(String sessionId, String logId) {
		logIdTable.put(sessionId, logId);
	}

	public void putLogoutMemo(String sessionId, String logoutMemo) {
		logoutMemoTable.put(sessionId, logoutMemo);
	}

	public void valueUnbound(HttpSessionBindingEvent arg0) {
//		sessionTable.remove(arg0.getSession().getId());
//		String logId = logIdTable.get(arg0.getSession().getId());
//		logIdTable.remove(arg0.getSession().getId());
//		String logoutMemo = logoutMemoTable.get(arg0.getSession().getId());
//		logoutMemoTable.remove(arg0.getSession().getId());
//		System.out.println("************valueUnbound****************");
//		if (logoutMemo == null)
//			logoutMemo = "超时退出";
//		Hotel.writeLogoutLog(logId, logoutMemo);
	}
}
